package com.lottery.system.common.utils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;

/**
 * @author: xiaoxie
 * create: 2024-09-04 11:18
 * @BelongsProject: lottery-system
 * @BelongsPackage: com.lottery.system.common.utils
 * description: 验证码工具包
 */
public class MyCaptchaUtil {
    /**
     * @description: 生成随机的验证码.
     * @author: xiaoxie
     * @date: 2024/9/4 11:21
     * @param: [length]
     * @return: java.lang.String
     **/
    public static String getCaptcha(int length) {
        RandomGenerator randomGenerator = new RandomGenerator("0123456789", length);
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        lineCaptcha.setGenerator(randomGenerator);
        // 重新生成code
        lineCaptcha.createCode();
        return lineCaptcha.getCode();
    }
}
